const regist = document.querySelector('.login-form')
const userInp = regist.querySelector('.user')
const pswInp = regist.querySelector('.psw')
const pswaInp = regist.querySelector('.pswa')
const btn = regist.querySelector('.button')
const mask = document.querySelector('.mask')
console.log(mask);
regist.addEventListener('click',(e) => {
  e = e || window.event
  const target = e.target || e.srcElement
  if(target.className === 'button'){
    const user = userInp.value
    const psw = pswInp.value
    const pswa = pswaInp.value
    if(psw !== pswa){
      mask.style.display = 'block'
      return
    }
    const data = JSON.stringify({user:user,psw:psw,pswa:pswa})
    const xhr = new XMLHttpRequest()
    xhr.open('POST','http://localhost:8080/regist')
    xhr.onload = () => {
      const res = JSON.parse(xhr.responseText)
      if(res.code) window.location.href = '../html/login.html'
  }
    xhr.setRequestHeader("Content-type", "application/json")
    xhr.send(data)
  }
})